﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Personalplaner.Modules.Personoverview;

namespace Personalplaner.Gui
{
    [ToolboxItem(false)]
    public partial class JahresplanSelection : UserControl, Gencode.Gengui.Forms.IDialogControl
    {
        JahresplanView jp = null;
        DataView dv = null;
        public JahresplanSelection(IPersonDetail prsDetail)
        {
            InitializeComponent();

            if (prsDetail != null && prsDetail is JahresplanView)
                jp = prsDetail as JahresplanView;

            dv = Gencode.PrsCommon.Data.Dienst.DienstData.GetDienste(Verwaltung.Mandant);
            
            dienstGrid.Rows.Add(dv.Count);
            for (int i=0;i<dv.Count;i++)
            {
                dienstGrid[1, i].Value = dv[i].Row[0].ToString();
            }

            checkAll.Checked = true;
        }

        #region IDialogControl Member

        public bool OKClicked()
        {
            string dienstIDs = string.Empty;
            for (int i = 0; i < dv.Count; i++)
            {
				if ((bool)dienstGrid[0, i].Value == true)
				{
					int id = int.Parse(dv[i].Row[1].ToString());
					if (id < 10)
						dienstIDs += "0" + id;
					else
						dienstIDs += id.ToString();
				}
            }

            jp.DienstIDs = dienstIDs;

            jp.MitFeiertagen = checkFeiertage.Checked;
            jp.MitWochenend = checkWeekend.Checked;
            jp.Alles = checkAll.Checked;

            jp.ResetGrid(0);
			
			return true;
        }

        public bool CancleClicked()
        {
            //Do nothing
			return true;
        }

        #endregion

        private void btnReset_Click(object sender, EventArgs e)
        {
            ResetControls();
        }

        private void ResetControls()
        {
            for (int i = 0; i < dienstGrid.Rows.Count; i++)
            {
                dienstGrid[0, i].Value = false;
            }
            checkFeiertage.Checked = false;
            checkWeekend.Checked = false;
        }

        private void checkAll_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkAll.Checked)
            {
                dienstGrid.Enabled = true;
                checkFeiertage.Enabled = true;
                checkWeekend.Enabled = true;
            }
            else
            {
                dienstGrid.Enabled = false;
                checkFeiertage.Enabled = false;
                checkWeekend.Enabled = false;

                ResetControls();
            }
        }
    }
}
